<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="账户类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountType">
              <j-dict-select-tag
                type="list"
                v-model="model.accountType"
                dictCode="account_type"
                placeholder="请选择账户类型"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="资质认证状态：0-未认证 1-认证中 2-已认证 3-认证驳回"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="certificateAuditStatus"
            >
              <j-dict-select-tag
                type="list"
                v-model="model.certificateAuditStatus"
                dictCode="certificate_audit_status"
                placeholder="请选择资质认证状态：0-未认证 1-认证中 2-已认证 3-认证驳回"
              />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="注册渠道(0-PC，1-公众号，2-后台）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="channel">
              <j-dict-select-tag type="list" v-model="model.channel" dictCode="sign_up_channel" placeholder="请选择注册渠道(0-PC，1-公众号，2-后台）" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="用户名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="username">
              <a-input v-model="model.username" placeholder="请输入用户名"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phoneNumber">
              <a-input v-model="model.phoneNumber" placeholder="请输入手机号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="SEO关键字" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="seoKeywords">
              <a-textarea v-model="model.seoKeywords" rows="4" placeholder="请输入SEO关键字" />
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="SEO描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="seoDescription">
              <a-textarea v-model="model.seoDescription" rows="4" placeholder="SEO描述" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="email">
              <a-input v-model="model.email" placeholder="请输入邮箱"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="企业名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enterpriseName">
              <a-input v-model="model.enterpriseName" placeholder="请输入企业名称"></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="密码(必须包含大小写字母和数字的组合，可以使用特殊字符(~!@#$%^&*)，长度在8-32之间)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="password">
              <a-input v-model="model.password" placeholder="请输入密码(必须包含大小写字母和数字的组合，可以使用特殊字符(~!@#$%^&*)，长度在8-32之间)"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="开户银行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankAccountName">
              <a-input v-model="model.bankAccountName" placeholder="请输入开户银行"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="银行账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankAccountNum">
              <a-input v-model="model.bankAccountNum" placeholder="请输入银行账号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经营模式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessModelId">
              <j-dict-select-tag
                type="list"
                v-model="model.businessModelId"
                dictCode="ht_business_model_category,name,id"
                placeholder="请选择经营模式"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="税号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxId">
              <a-input v-model="model.taxId" placeholder="请输入税号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机构Logo" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logo">
              <j-image-upload isMultiple v-model="model.logo"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="企业主图" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cover">
              <j-image-upload isMultiple v-model="model.cover"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="avatar">
              <a-input v-model="model.avatar" placeholder="请输入头像"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="简介" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="introduction">
              <j-editor v-model="model.introduction" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="营业执照" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="certificate">
              <j-image-upload isMultiple v-model="model.certificate"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="其他资质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="otherCertificates">
              <j-image-upload isMultiple v-model="model.otherCertificates"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="产业分类ID"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="industryCategoryId"
            >
              <j-dict-select-tag
                type="list"
                v-model="model.industryCategoryId"
                dictCode="ht_industry_category,name,id"
                placeholder="请选择产业分类ID"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditUsername">
              <a-input v-model="model.auditUsername" placeholder="请输入审核人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="注册资金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="registeredCapital">
              <a-input v-model="model.registeredCapital" placeholder="请输入注册资金"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="年营业额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yearlyTurnover">
              <a-input v-model="model.yearlyTurnover" placeholder="请输入年营业额"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditStatus">
              <j-dict-select-tag
                type="list"
                v-model="model.auditStatus"
                dictCode="audit_status"
                placeholder="请选择审核状态"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审批意见" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditComments">
              <a-textarea v-model="model.auditComments" rows="4" placeholder="请输入审批意见" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否冻结" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isLocked">
              <j-dict-select-tag
                type="list"
                v-model="model.isLocked"
                dictCode="is_locked"
                placeholder="请选择是否冻结"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'HTAllianceForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {
        accountType: 5,
        certificateAuditStatus: 0,
        channel: 0,
        auditStatus: 0,
        isLocked: 0
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        accountType: [{ required: true, message: '请输入账户类型!' }],
        certificateAuditStatus: [
          { required: true, message: '请输入资质认证状态：0-未认证 1-认证中 2-已认证 3-认证驳回!' }
        ],
        //  channel: [
        //     { required: true, message: '请输入注册渠道(0-PC，1-公众号，2-后台）!'},
        //  ],
        username: [{ required: true, message: '请输入用户名!' }],
        phoneNumber: [
          { required: true, message: '请输入手机号!' },
          { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!' }
        ],
        email: [
          { required: false },
          { pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/, message: '请输入正确的电子邮件!' }
        ],
        enterpriseName: [{ required: true, message: '请输入企业名称!' }],
        logo: [{ required: true, message: '请输入机构Logo!' }],
        cover: [{ required: true, message: '请输入企业主图!' }],
        introduction: [{ required: true, message: '请输入简介!' }],
        certificate: [{ required: true, message: '请输入营业执照!' }],
        auditStatus: [{ required: true, message: '请输入审核状态!' }],
        isLocked: [{ required: true, message: '请输入是否冻结!' }]
      },
      url: {
        add: '/account/hTAlliance/add',
        edit: '/account/hTAlliance/edit',
        queryById: '/account/hTAlliance/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    }
  }
}
</script>
